#include "exp_trans.h"
#include "data_memory.h"

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

using namespace std;

int main()
{
    ifstream infile("input.txt");
    if (!infile.is_open()) {
        cerr << "Error opening file!" << endl;
        return 1;
    }

    string line;
    while (getline(infile, line)) {
        if (line.empty()) {
            continue;  // Skip empty lines
        }

        // Reset DataMemory for each group
        // DataMemory::clear();  // Assuming there's a clear method to reset the data
        DataMemory::save_snapshot();

        // Read and set variables
        do {
            istringstream iss(line);
            string var;
            int val;

            if (iss >> var >> val) {
                cout << "Setting " << var << " to " << val << endl;
                DataMemory::set_val(var, val);
            }
        } while (getline(infile, line) && !line.empty());

        while (getline(infile, line) && !line.empty()) {
            cout << "Evaluating expression: " << line << endl;
            // The last non-empty line is the expression to evaluate
            cout << eval_exp(line) << endl;
        }
    }

    infile.close();
    return 0;
}
